<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单编号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户id，关联用户表" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id，关联用户表"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址id，关联地址表" prop="addressId">
        <el-input
          v-model="queryParams.addressId"
          placeholder="请输入地址id，关联地址表"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺id，关联店铺表" prop="shopId">
        <el-input
          v-model="queryParams.shopId"
          placeholder="请输入店铺id，关联店铺表"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺地址" prop="shopAddress">
        <el-input
          v-model="queryParams.shopAddress"
          placeholder="请输入店铺地址"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否使用了优惠券" prop="isCoupons">
        <el-input
          v-model="queryParams.isCoupons"
          placeholder="请输入是否使用了优惠券"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用的优惠券id，关联优惠券表" prop="couponsId">
        <el-input
          v-model="queryParams.couponsId"
          placeholder="请输入使用的优惠券id，关联优惠券表"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单种类(1-外卖订单 2-商城订单)" prop="orderClass">
        <el-input
          v-model="queryParams.orderClass"
          placeholder="请输入订单种类(1-外卖订单 2-商城订单)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单备注" prop="orderDesc">
        <el-input
          v-model="queryParams.orderDesc"
          placeholder="请输入订单备注"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="取餐号" prop="queueNum">
        <el-input
          v-model="queryParams.queueNum"
          placeholder="请输入取餐号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="配送费" prop="deliveryFees">
        <el-input
          v-model="queryParams.deliveryFees"
          placeholder="请输入配送费"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总包装费" prop="totalWrapFees">
        <el-input
          v-model="queryParams.totalWrapFees"
          placeholder="请输入总包装费"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单总价格" prop="orderPrice">
        <el-input
          v-model="queryParams.orderPrice"
          placeholder="请输入订单总价格"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实付价格" prop="realPrice">
        <el-input
          v-model="queryParams.realPrice"
          placeholder="请输入实付价格"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="平台抽取比例(百分比)" prop="platformExtractRatio">
        <el-input
          v-model="queryParams.platformExtractRatio"
          placeholder="请输入平台抽取比例(百分比)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="平台抽取金额" prop="platformExtractPrice">
        <el-input
          v-model="queryParams.platformExtractPrice"
          placeholder="请输入平台抽取金额"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="平台承担的配送费" prop="platformDeliveryFee">
        <el-input
          v-model="queryParams.platformDeliveryFee"
          placeholder="请输入平台承担的配送费"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="平台实际收入" prop="platformIncome">
        <el-input
          v-model="queryParams.platformIncome"
          placeholder="请输入平台实际收入"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商家承担的配送费" prop="businessDeliveryFee">
        <el-input
          v-model="queryParams.businessDeliveryFee"
          placeholder="请输入商家承担的配送费"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商家实际收入" prop="businessIncome">
        <el-input
          v-model="queryParams.businessIncome"
          placeholder="请输入商家实际收入"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付时间" prop="payTime">
        <el-date-picker clearable
          v-model="queryParams.payTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择支付时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单创建时间" prop="orderCreateTime">
        <el-date-picker clearable
          v-model="queryParams.orderCreateTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择订单创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单支付截止时间，超时自动取消" prop="orderEndTime">
        <el-date-picker clearable
          v-model="queryParams.orderEndTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择订单支付截止时间，超时自动取消">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单预计送达时间" prop="orderEstimateTime">
        <el-date-picker clearable
          v-model="queryParams.orderEstimateTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择订单预计送达时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单完成时间" prop="orderCompleteTime">
        <el-date-picker clearable
          v-model="queryParams.orderCompleteTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择订单完成时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="自取时间" prop="takeTime">
        <el-date-picker clearable
          v-model="queryParams.takeTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择自取时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="预留电话" prop="obligatePhone">
        <el-input
          v-model="queryParams.obligatePhone"
          placeholder="请输入预留电话"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否已打印(0-否 1-是)" prop="isPrinted">
        <el-input
          v-model="queryParams.isPrinted"
          placeholder="请输入是否已打印(0-否 1-是)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下单资金是否已转入商家账户(0-否 1-是)" prop="isPayToMerchant">
        <el-input
          v-model="queryParams.isPayToMerchant"
          placeholder="请输入下单资金是否已转入商家账户(0-否 1-是)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否已删除(0-否 1-是)" prop="isDelete">
        <el-input
          v-model="queryParams.isDelete"
          placeholder="请输入是否已删除(0-否 1-是)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否已售后(0-否 1-是)" prop="isAfterSales">
        <el-input
          v-model="queryParams.isAfterSales"
          placeholder="请输入是否已售后(0-否 1-是)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否已评价(0-否 1-是)" prop="isEvaluate">
        <el-input
          v-model="queryParams.isEvaluate"
          placeholder="请输入是否已评价(0-否 1-是)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['order:orders:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['order:orders:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['order:orders:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['order:orders:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ordersList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单id，主键自增" align="center" prop="orderId" />
      <el-table-column label="订单编号" align="center" prop="orderNo" />
      <el-table-column label="用户id，关联用户表" align="center" prop="userId" />
      <el-table-column label="地址id，关联地址表" align="center" prop="addressId" />
      <el-table-column label="店铺id，关联店铺表" align="center" prop="shopId" />
      <el-table-column label="店铺地址" align="center" prop="shopAddress" />
      <el-table-column label="是否使用了优惠券" align="center" prop="isCoupons" />
      <el-table-column label="使用的优惠券id，关联优惠券表" align="center" prop="couponsId" />
      <el-table-column label="订单种类(1-外卖订单 2-商城订单)" align="center" prop="orderClass" />
      <el-table-column label="订单备注" align="center" prop="orderDesc" />
      <el-table-column label="取餐号" align="center" prop="queueNum" />
      <el-table-column label="配送费" align="center" prop="deliveryFees" />
      <el-table-column label="总包装费" align="center" prop="totalWrapFees" />
      <el-table-column label="订单总价格" align="center" prop="orderPrice" />
      <el-table-column label="实付价格" align="center" prop="realPrice" />
      <el-table-column label="平台抽取比例(百分比)" align="center" prop="platformExtractRatio" />
      <el-table-column label="平台抽取金额" align="center" prop="platformExtractPrice" />
      <el-table-column label="平台承担的配送费" align="center" prop="platformDeliveryFee" />
      <el-table-column label="平台实际收入" align="center" prop="platformIncome" />
      <el-table-column label="商家承担的配送费" align="center" prop="businessDeliveryFee" />
      <el-table-column label="商家实际收入" align="center" prop="businessIncome" />
      <el-table-column label="支付类型(1-微信支付 2-支付宝 3-其他)" align="center" prop="payType" />
      <el-table-column label="支付时间" align="center" prop="payTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单创建时间" align="center" prop="orderCreateTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.orderCreateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单支付截止时间，超时自动取消" align="center" prop="orderEndTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.orderEndTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单预计送达时间" align="center" prop="orderEstimateTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.orderEstimateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单完成时间" align="center" prop="orderCompleteTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.orderCompleteTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="配送方式(1-配送 2-自提)" align="center" prop="deliveryType" />
      <el-table-column label="自取时间" align="center" prop="takeTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.takeTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预留电话" align="center" prop="obligatePhone" />
      <el-table-column label="订单状态(1-待支付 2-待发货 3-待配送 4-配送中 5-已完成 6-已取消 7-售后处理中)" align="center" prop="orderStatus" />
      <el-table-column label="是否已打印(0-否 1-是)" align="center" prop="isPrinted" />
      <el-table-column label="下单资金是否已转入商家账户(0-否 1-是)" align="center" prop="isPayToMerchant" />
      <el-table-column label="是否已删除(0-否 1-是)" align="center" prop="isDelete" />
      <el-table-column label="是否已售后(0-否 1-是)" align="center" prop="isAfterSales" />
      <el-table-column label="是否已评价(0-否 1-是)" align="center" prop="isEvaluate" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['order:orders:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['order:orders:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单查询对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="ordersRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单编号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="用户id，关联用户表" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id，关联用户表" />
        </el-form-item>
        <el-form-item label="地址id，关联地址表" prop="addressId">
          <el-input v-model="form.addressId" placeholder="请输入地址id，关联地址表" />
        </el-form-item>
        <el-form-item label="店铺id，关联店铺表" prop="shopId">
          <el-input v-model="form.shopId" placeholder="请输入店铺id，关联店铺表" />
        </el-form-item>
        <el-form-item label="店铺地址" prop="shopAddress">
          <el-input v-model="form.shopAddress" placeholder="请输入店铺地址" />
        </el-form-item>
        <el-form-item label="是否使用了优惠券" prop="isCoupons">
          <el-input v-model="form.isCoupons" placeholder="请输入是否使用了优惠券" />
        </el-form-item>
        <el-form-item label="使用的优惠券id，关联优惠券表" prop="couponsId">
          <el-input v-model="form.couponsId" placeholder="请输入使用的优惠券id，关联优惠券表" />
        </el-form-item>
        <el-form-item label="订单种类(1-外卖订单 2-商城订单)" prop="orderClass">
          <el-input v-model="form.orderClass" placeholder="请输入订单种类(1-外卖订单 2-商城订单)" />
        </el-form-item>
        <el-form-item label="订单备注" prop="orderDesc">
          <el-input v-model="form.orderDesc" placeholder="请输入订单备注" />
        </el-form-item>
        <el-form-item label="取餐号" prop="queueNum">
          <el-input v-model="form.queueNum" placeholder="请输入取餐号" />
        </el-form-item>
        <el-form-item label="配送费" prop="deliveryFees">
          <el-input v-model="form.deliveryFees" placeholder="请输入配送费" />
        </el-form-item>
        <el-form-item label="总包装费" prop="totalWrapFees">
          <el-input v-model="form.totalWrapFees" placeholder="请输入总包装费" />
        </el-form-item>
        <el-form-item label="订单总价格" prop="orderPrice">
          <el-input v-model="form.orderPrice" placeholder="请输入订单总价格" />
        </el-form-item>
        <el-form-item label="实付价格" prop="realPrice">
          <el-input v-model="form.realPrice" placeholder="请输入实付价格" />
        </el-form-item>
        <el-form-item label="平台抽取比例(百分比)" prop="platformExtractRatio">
          <el-input v-model="form.platformExtractRatio" placeholder="请输入平台抽取比例(百分比)" />
        </el-form-item>
        <el-form-item label="平台抽取金额" prop="platformExtractPrice">
          <el-input v-model="form.platformExtractPrice" placeholder="请输入平台抽取金额" />
        </el-form-item>
        <el-form-item label="平台承担的配送费" prop="platformDeliveryFee">
          <el-input v-model="form.platformDeliveryFee" placeholder="请输入平台承担的配送费" />
        </el-form-item>
        <el-form-item label="平台实际收入" prop="platformIncome">
          <el-input v-model="form.platformIncome" placeholder="请输入平台实际收入" />
        </el-form-item>
        <el-form-item label="商家承担的配送费" prop="businessDeliveryFee">
          <el-input v-model="form.businessDeliveryFee" placeholder="请输入商家承担的配送费" />
        </el-form-item>
        <el-form-item label="商家实际收入" prop="businessIncome">
          <el-input v-model="form.businessIncome" placeholder="请输入商家实际收入" />
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-date-picker clearable
            v-model="form.payTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择支付时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单创建时间" prop="orderCreateTime">
          <el-date-picker clearable
            v-model="form.orderCreateTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择订单创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单支付截止时间，超时自动取消" prop="orderEndTime">
          <el-date-picker clearable
            v-model="form.orderEndTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择订单支付截止时间，超时自动取消">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单预计送达时间" prop="orderEstimateTime">
          <el-date-picker clearable
            v-model="form.orderEstimateTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择订单预计送达时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单完成时间" prop="orderCompleteTime">
          <el-date-picker clearable
            v-model="form.orderCompleteTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择订单完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="自取时间" prop="takeTime">
          <el-date-picker clearable
            v-model="form.takeTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择自取时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预留电话" prop="obligatePhone">
          <el-input v-model="form.obligatePhone" placeholder="请输入预留电话" />
        </el-form-item>
        <el-form-item label="是否已打印(0-否 1-是)" prop="isPrinted">
          <el-input v-model="form.isPrinted" placeholder="请输入是否已打印(0-否 1-是)" />
        </el-form-item>
        <el-form-item label="下单资金是否已转入商家账户(0-否 1-是)" prop="isPayToMerchant">
          <el-input v-model="form.isPayToMerchant" placeholder="请输入下单资金是否已转入商家账户(0-否 1-是)" />
        </el-form-item>
        <el-form-item label="是否已删除(0-否 1-是)" prop="isDelete">
          <el-input v-model="form.isDelete" placeholder="请输入是否已删除(0-否 1-是)" />
        </el-form-item>
        <el-form-item label="是否已售后(0-否 1-是)" prop="isAfterSales">
          <el-input v-model="form.isAfterSales" placeholder="请输入是否已售后(0-否 1-是)" />
        </el-form-item>
        <el-form-item label="是否已评价(0-否 1-是)" prop="isEvaluate">
          <el-input v-model="form.isEvaluate" placeholder="请输入是否已评价(0-否 1-是)" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Orders">
import { listOrders, getOrders, delOrders, addOrders, updateOrders } from "@/api/order/orders"

const { proxy } = getCurrentInstance()

const ordersList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    orderNo: null,
    userId: null,
    addressId: null,
    shopId: null,
    shopAddress: null,
    isCoupons: null,
    couponsId: null,
    orderClass: null,
    orderDesc: null,
    queueNum: null,
    deliveryFees: null,
    totalWrapFees: null,
    orderPrice: null,
    realPrice: null,
    platformExtractRatio: null,
    platformExtractPrice: null,
    platformDeliveryFee: null,
    platformIncome: null,
    businessDeliveryFee: null,
    businessIncome: null,
    payType: null,
    payTime: null,
    orderCreateTime: null,
    orderEndTime: null,
    orderEstimateTime: null,
    orderCompleteTime: null,
    deliveryType: null,
    takeTime: null,
    obligatePhone: null,
    orderStatus: null,
    isPrinted: null,
    isPayToMerchant: null,
    isDelete: null,
    isAfterSales: null,
    isEvaluate: null
  },
  rules: {
    orderNo: [
      { required: true, message: "订单编号不能为空", trigger: "blur" }
    ],
    userId: [
      { required: true, message: "用户id，关联用户表不能为空", trigger: "blur" }
    ],
    orderPrice: [
      { required: true, message: "订单总价格不能为空", trigger: "blur" }
    ],
    realPrice: [
      { required: true, message: "实付价格不能为空", trigger: "blur" }
    ],
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询订单查询列表 */
function getList() {
  loading.value = true
  listOrders(queryParams.value).then(response => {
    ordersList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    orderId: null,
    orderNo: null,
    userId: null,
    addressId: null,
    shopId: null,
    shopAddress: null,
    isCoupons: null,
    couponsId: null,
    orderClass: null,
    orderDesc: null,
    queueNum: null,
    deliveryFees: null,
    totalWrapFees: null,
    orderPrice: null,
    realPrice: null,
    platformExtractRatio: null,
    platformExtractPrice: null,
    platformDeliveryFee: null,
    platformIncome: null,
    businessDeliveryFee: null,
    businessIncome: null,
    payType: null,
    payTime: null,
    orderCreateTime: null,
    orderEndTime: null,
    orderEstimateTime: null,
    orderCompleteTime: null,
    deliveryType: null,
    takeTime: null,
    obligatePhone: null,
    orderStatus: null,
    isPrinted: null,
    isPayToMerchant: null,
    isDelete: null,
    isAfterSales: null,
    isEvaluate: null
  }
  proxy.resetForm("ordersRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.orderId)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加订单查询"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _orderId = row.orderId || ids.value
  getOrders(_orderId).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改订单查询"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["ordersRef"].validate(valid => {
    if (valid) {
      if (form.value.orderId != null) {
        updateOrders(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addOrders(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _orderIds = row.orderId || ids.value
  proxy.$modal.confirm('是否确认删除订单查询编号为"' + _orderIds + '"的数据项？').then(function() {
    return delOrders(_orderIds)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('order/orders/export', {
    ...queryParams.value
  }, `orders_${new Date().getTime()}.xlsx`)
}

getList()
</script>
